package servlet;

import dao.Db;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delete")
public class DelData extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取删除记录的ID
        String id = req.getParameter("id");
        System.out.println("id = " + id);
        //访问数据访问层
        Db db = new Db();
        int i= db.delectData(id);
        System.out.println("i = " + i);
        if (i>0){
            req.getRequestDispatcher("worker").forward(req,resp);
        }else {
            System.out.println("删除失败");
        }
    }
}
